package org.mics.organization.controller;

import java.util.List;

import javax.annotation.Resource;

import org.mics.core.page.PageQuery;
import org.mics.core.response.MultipleDataResponse;
import org.mics.core.response.OneDataResponse;
import org.mics.core.response.PageDataResponse;
import org.mics.core.response.SimpleResponse;
import org.mics.lang.bean.BeanConvertUtil;
import org.mics.organization.entity.PostDO;
import org.mics.organization.request.PostRequest;
import org.mics.organization.service.PostService;
import org.mics.organization.vo.PostVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

/**
 * 岗位
 * @author mics
 * @date 2023-10-9
 * @version  1.0
 */
@RestController
@RequestMapping("/post")
@Tag(name = "岗位")
public class PostController {
	@Resource
	private PostService postService;
	
	@Operation(summary =  "增加/修改岗位")
    @RequestMapping(value = "/save",method = RequestMethod.POST)
	public SimpleResponse save(@Validated @RequestBody PostRequest postRequest ) {
		String id =   postService.add(postRequest);
		return new OneDataResponse<String>(id);
	}
	
	@Operation(summary =  "删除岗位")
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.DELETE)
	public SimpleResponse delete(@PathVariable("id") String id) {
		postService.delete(id);
        return new SimpleResponse();
	}
	
	@Operation(summary =  "岗位列表")
    @RequestMapping(value = "/listByPage",method = RequestMethod.POST)
	public PageDataResponse<PostVO> listByPage(@RequestBody PageQuery pageQuery) {
		PageDataResponse<PostVO> pageDataResponse =   postService.listByPage(pageQuery);
		return pageDataResponse;
	}
	
	@Operation(summary =  "岗位列表")
    @RequestMapping(value = "list",method = RequestMethod.GET)
	public MultipleDataResponse<PostVO> list(){
		List<PostDO> postDOs = postService.list();
		return new MultipleDataResponse<PostVO>(BeanConvertUtil.convertList(postDOs, PostVO.class));
	}
}
